package com.baizhi.controller;


import com.baizhi.entity.Category;
import com.baizhi.entity.Video;
import com.baizhi.service.CategoryService;
import com.baizhi.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    //分页查
    @RequestMapping("queryByPage")
    public Map<String,Object> queryByPage(int page){
        int size = 2; //每页显示两条
        return videoService.queryByPage(page,size);
    }

    //添加
    @RequestMapping("add")
    public void add(String categoryId, String title, String brief, MultipartFile video){
        /*System.out.println(categoryId);
        System.out.println(title);
        System.out.println(brief);
        System.out.println(video);
        System.out.println(video.getOriginalFilename());*/
        Video video1 = new Video(null,title,brief,null,null,null,new Category(categoryId,null,null,null),null,null);
        videoService.add(video,video1);
    }

    @RequestMapping("delete")
    public void delete(String id,String videoPath,String coverPath){
        System.out.println(id);
        System.out.println(videoPath);
        System.out.println(coverPath);
        videoService.delete(id,videoPath,coverPath);
    }

}


